/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DAL.ConnectUnit;
import DTO.SavingType_DTO;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import javax.swing.JOptionPane;

/**
 *
 * @author Nguyen Phi Hung
 */
public class SavingType_BLL {
    
    ConnectUnit connection;
    
    public SavingType_BLL(){
        this.connection = DAL.DAL.getDAL();
    }
    public ResultSet ExcuteQuery(String procedure,String sql) throws SQLException, Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, sql);
        return cs.executeQuery();
    
    }
    public boolean Insert(String procedure,SavingType_DTO info) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, info.getName());
        cs.setInt(2, info.getTerm());
        cs.setFloat(3, info.getInterestRate());
        return cs.execute();
    }
    public boolean Update(String procedure,SavingType_DTO info) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, info.getTypeID());
        cs.setString(2, info.getName());
        cs.setInt(3, info.getTerm());
        cs.setFloat(4, info.getInterestRate());
        return cs.execute();
    }
    public boolean Delete(String procedure,SavingType_DTO info) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, info.getTypeID());
        return cs.execute();
    }
    //kiem tra co the xoa loai tiet kiem hay khong
    public boolean KiemTraLoaiTietKiemCoTheXoa(String procedure,String MaLoaiTietKiem) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, MaLoaiTietKiem);
        cs.registerOutParameter(2, java.sql.Types.BOOLEAN);
        cs.execute();
        return cs.getBoolean(2);
    }
    public static void main(String[] str) throws Exception
    {
        SavingType_BLL savingtype_bll=new SavingType_BLL();
        SavingType_DTO info=new SavingType_DTO();
        info.setTypeID("TD00000004");
        info.setName("sam");
        info.setTerm(2);
        info.setInterestRate((float) 0.04);
        JOptionPane.showMessageDialog(null, savingtype_bll.KiemTraLoaiTietKiemCoTheXoa("{call KiemTraLoaiTietKiemCoTheXoa(?,?)}", "TD00000002"));
    }
}
